package com.itheima.service.impl;

import com.itheima.dao.ActHiVarinstDao;
import com.itheima.pojo.ActHiVarinst;
import com.itheima.service.ActHiVarinstService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (ActHiVarinst)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:50
 */
@Service("actHiVarinstService")
public class ActHiVarinstServiceImpl implements ActHiVarinstService {
    @Resource
    private ActHiVarinstDao actHiVarinstDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id_ 主键
     * @return 实例对象
     */
    @Override
    public ActHiVarinst queryById(String id_) {
        return this.actHiVarinstDao.queryById(id_);
    }

    /**
     * 分页查询
     *
     * @param actHiVarinst 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ActHiVarinst> queryByPage(ActHiVarinst actHiVarinst, PageRequest pageRequest) {
        long total = this.actHiVarinstDao.count(actHiVarinst);
        return new PageImpl<>(this.actHiVarinstDao.queryAllByLimit(actHiVarinst, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param actHiVarinst 实例对象
     * @return 实例对象
     */
    @Override
    public ActHiVarinst insert(ActHiVarinst actHiVarinst) {
        this.actHiVarinstDao.insert(actHiVarinst);
        return actHiVarinst;
    }

    /**
     * 修改数据
     *
     * @param actHiVarinst 实例对象
     * @return 实例对象
     */
    @Override
    public ActHiVarinst update(ActHiVarinst actHiVarinst) {
        this.actHiVarinstDao.update(actHiVarinst);
        return this.queryById(actHiVarinst.getId_());
    }

    /**
     * 通过主键删除数据
     *
     * @param id_ 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id_) {
        return this.actHiVarinstDao.deleteById(id_) > 0;
    }
}
